Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qr code generation optional argument #277

Merged
merged 12 commits into from
Dec 12, 2024
Merged

Conversation

jherzstein
Copy link
Contributor

The people developing for magic wormhole python seem to want to implement qr code generation as an option, ready for their next release. I thought it would make sense to add an argument to optionally suppress qr code generation due to the minor security risk it poses for always having it on. This implementation suppresses it by default without the --qr option but if you have a preference for the other way I have another branch I can merge for the --no-qr optional implementation. Let me know what you think. Thanks.

For --help:

$ wormhole-rs send --help
Send a file or a folder

Usage: wormhole-rs send [OPTIONS] <FILENAME|DIRNAME>...

Arguments:
  <FILENAME|DIRNAME>...

Options:
      --relay-server <tcp://HOSTNAME:PORT>
          Use a custom relay server (specify multiple times for multiple relays) [aliases: relay]
      --rendezvous-server <ws://example.org>
          Use a custom rendezvous server. Both sides need to use the same value in order to find each other
      --force-direct
          Disable the relay server support and force a direct connection
      --force-relay
          Always route traffic over a relay server. This hides your IP address from the peer (but not from the server operators. Use Tor for that)
      --code <CODE>
          Enter a code instead of generating one automatically
  -c, --code-length <NUMWORDS>
          Length of code (in bytes/words) [default: 2]
      --qr
          Generate QR code from send link
      --rename <FILE_NAME>
          Suggest a different name to the receiver to keep the file's actual name secret. Not allowed when sending more than one file [aliases: name]
  -v, --verbose
          Enable logging to stdout, for debugging purposes
  -h, --help
          Print help
  -V, --version
          Print version

qr code suppressed:

$ wormhole-rs send file
This wormhole's code is: 5-recover-scorecard (it has been copied to your clipboard)
This is equivalent to the following link: wormhole-transfer:5-recover-scorecard
QR option not enabled. Skipping QR code generation.
On the other side, open the link or enter that code into a Magic Wormhole client.
For example: wormhole-rs receive 5-recover-scorecard

--qr added:

$ wormhole-rs send --qr file

This wormhole's code is: 3-fascinate-classic (it has been copied to your clipboard)
This is equivalent to the following link: wormhole-transfer:3-fascinate-classic
                                 
   ▄▄▄▄▄   ▄▄ ▄▄ ▄ ▄▄▄   ▄▄▄▄▄   
           ▄▄▄  ▄▄ ▄             
    ▄▄▄    ▄ ▄▄ ▄▄ ▄ ▄▄   ▄▄▄    
  ▄▄▄▄▄▄▄    ▄ ▄▄ ▄ ▄▄  ▄▄▄▄▄▄▄  
    ▄▄ ▄▄▄   ▄  ▄▄  ▄▄▄▄     ▄▄  
  ▄▄   ▄▄    ▄  ▄▄▄ ▄  ▄ ▄   ▄▄  
  ▄▄  ▄▄▄ ▄▄▄  ▄▄▄  ▄   ▄▄▄  ▄▄  
  ▄▄▄ ▄▄▄▄▄ ▄▄  ▄ ▄▄▄▄▄▄▄ ▄▄  ▄  
    ▄▄▄ ▄  ▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄ ▄   
    ▄▄▄ ▄▄ ▄▄   ▄ ▄ ▄▄ ▄▄▄  ▄ ▄  
  ▄   ▄▄▄  ▄ ▄▄▄▄ ▄▄   ▄▄▄ ▄  ▄  
   ▄▄▄▄▄  ▄▄▄ ▄ ▄▄▄ ▄▄  ▄  ▄     
           ▄ ▄  ▄▄▄▄▄  ▄▄ ▄▄▄▄▄  
    ▄▄▄   ▄ ▄▄  ▄    ▄▄▄▄  ▄     
  ▄▄▄▄▄▄▄ ▄▄▄  ▄   ▄▄▄   ▄  ▄    
                                 

On the other side, open the link or enter that code into a Magic Wormhole client.
For example: wormhole-rs receive 3-fascinate-classic

Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 37.59%. Comparing base (c00e94f) to head (8538dd1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/main.rs 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #277      +/-   ##
==========================================
- Coverage   37.80%   37.59%   -0.21%     
==========================================
  Files          19       19              
  Lines        3214     3221       +7     
==========================================
- Hits         1215     1211       -4     
- Misses       1999     2010      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@felinira
Copy link
Collaborator

felinira commented Dec 9, 2024

Thanks for your contribution. I don't understand the security aspect that is claimed to exist here. Is this just about the alleged time.it takes to scan a code vs the time it takes to copy a standard 2 word code by hand?

@jherzstein
Copy link
Contributor Author

First, thank you for taking the time to look over my pr.

Thanks for your contribution. I don't understand the security aspect that is claimed to exist here. Is this just about the alleged time.it takes to scan a code vs the time it takes to copy a standard 2 word code by hand?

Yeah more or less it's just easier to scan a qr code, which is done automatically, than taking the time to copy a code. I don't think it's that big of a deal at the end of the day, I just also like having the option of changing the default.

It seems as though the maintainers are leaning towards qr code by default, which has the benefit of being better for those who do not mind this default and usage being consistent across multiple versions of magic-wormhole-cli. I made another branch that keeps the same default as before unless you use the --no-qr flag, and will leave which you would like to implement up to your discretion. If you do prefer qr code by default, I can make a new PR, merge/rebase the other branch onto this one, or however you'd want me to do it.

@felinira
Copy link
Collaborator

Alright, as the python client went with QR code as default I think this is what we should do too :)

If anything else because we are already doing this, and I like to adhere to semver backwards compatibility for the CLI as well, as the version numbers are linked.

I can make a new PR, merge/rebase the other branch onto this one, or however you'd want me to do it.

It doesn't matter much to me. Force push this one, create a new PR and close this one, whatever is best for you.

While we are touching this part, I was wondering if the PrintCodeFn arguments could be factored into a struct that's shared with parse_and_connect (they share almost the same arguments, but not quite). It's getting a bit messy with all these arguments. But that's optional.

@jherzstein
Copy link
Contributor Author

Ok, I forced pushed my changes from the other branch so it's now qr by default. I fully agree with your reasoning here. Made an empty commit just to re-trigger the failed coverage test and then it work. Weird.

While we are touching this part, I was wondering if the PrintCodeFn arguments could be factored into a struct that's shared with parse_and_connect (they share almost the same arguments, but not quite). It's getting a bit messy with all these arguments. But that's optional.

I agree it was a bit weird the way things work with PrintCodeFn and can probably be done in a cleaner way. I was initially trying to pass the full CommonLeaderArgs struct into parse_and_connect and then quickly realized that there were all these other arguments in there and that sender_print_code relied on PrintCodeFn and decided that I wanted to make as few changes as possible to make this work. Accept these changes for now. I will create a new issue to reference this so at least it's out there, and then it can be addressed in a future PR.

Copy link
Collaborator

@felinira felinira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a tiny remark, otherwise LGTM

@felinira felinira merged commit bee63ed into magic-wormhole:main Dec 12, 2024
18 checks passed
@jherzstein jherzstein deleted the qr-opt branch December 12, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants